package com.bmadmin.controller.form;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.bmadmin.domain.Datagrid;
import com.bmadmin.domain.LayUiDataTablePOJO;
import com.bmadmin.domain.MessageDomain;
import com.bmadmin.domain.NormalResult;
import com.bmadmin.domain.NoticeDomain;
import com.bmadmin.domain.SjkcxDomain;
import com.bmadmin.domain.SysUsersPOJO;
import com.bmadmin.domain.XtqxDomain;
import com.bmadmin.service.SjkCxService;
import com.bmadmin.service.TzsService;
import com.bmadmin.util.BMUtil;
import com.bmadmin.util.Constants;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@RestController
@RequestMapping("/tzs")
public class TzsController {
	private Logger logger = LogManager.getLogger(this.getClass().getName());
	
    @Autowired
    TzsService tzsService;
    /**
     * 获取数据库查询申请表列表
     */
	@GetMapping("/getTzsApplyList")
    public Object getTzsApplyList(HttpSession session,NoticeDomain notice,Integer page,Integer limit) {
    	Datagrid result = new Datagrid();
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
    	
    	Map map = new HashMap();
		map.put("qs_date", notice.getQs_date());
		map.put("jz_date", notice.getJz_date());
		if(notice.getN_state()==null){
			map.put("n_state", "0,3,5");//默认显示表单状态 0--未提交 3--科级审核未通过 5--局级审核未通过
		}else if("".equals(notice.getN_state())){
			map.put("n_state", "0,1,2,3,4,5,6,7,8");
		}else{
			map.put("n_state", notice.getN_state());
		}
		map.put("n_apply_userid", user.getU_id());
		
		PageHelper.startPage(page, limit);
		List<NoticeDomain> list = tzsService.getTzsApplyList(map);
		PageInfo pagelist = new PageInfo(list);
		
		result.setCode(0);
        result.setMsg("success");
        result.setData(list);
        result.setCount(pagelist.getTotal());

        return result;
    }
	
    /**
     * 获取用户列表
     */
    @GetMapping("/getDepList")
    public LayUiDataTablePOJO getDepList() {
        LayUiDataTablePOJO result = tzsService.getDepList();
        logger.info(result);
        return result;
    }
    
    /**
     * 通知书保存
     */
    @PostMapping("/insertTzs")
    public NormalResult insertTzs(HttpSession session,NoticeDomain notice) {
    	String log = "内部事项发起通知书保存>>>>>>>>>>>";
    	logger.info(log+"参数【"+notice+"】");
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        try {
        	if(!BMUtil.isNotNull(notice.getN_duetime())){
        		result.setCode("9999");
                result.setMsg("办理期限为空！");
                logger.info(log+"办理期限为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(notice.getN_receive_depid())){
        		result.setCode("9999");
                result.setMsg("接收部门为空！");
                logger.info(log+"接收部门为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(notice.getN_content())){
        		result.setCode("9999");
                result.setMsg("工作事由为空！");
                logger.info(log+"工作事由为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(notice.getN_demand())){
        		result.setCode("9999");
                result.setMsg("工作要求为空！");
                logger.info(log+"工作要求为空！");
                return result;
        	}

        	notice.setN_apply_userid(user.getU_id());
        	notice.setN_apply_depid(user.getD_id());
        	notice.setN_apply_date(BMUtil.getNowTimeForString());
        	int retResult = tzsService.insertTzs(notice);
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("保存成功！");
                logger.info(log+"保存成功！");
        	}else{
        		result.setCode("9999");
                result.setMsg("保存失败！");
                logger.info(log+"保存失败！");
        	}
        	return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("通知书保存异常！");
            logger.error(e);
        }
        return result;
    }
    
    /**
     * 申请单删除
     */
    @PostMapping("/deleteTzs")
    public NormalResult deleteTzs(NoticeDomain notice) {
    	String log = "内部事项发起通知书删除>>>>>>>>>>>";
        NormalResult result = new NormalResult();
        if (BMUtil.isNullOrEmpty(notice.getN_id())) {
            result.setCode("9999");
            result.setMsg("传入申请单ID为空!");
            return result;
        }

        int retResult = tzsService.deleteTzs(notice.getN_id());
        if(retResult>0){
    		result.setCode("0000");
            result.setMsg("删除成功！");
            logger.info(log+"删除成功！");
    	}else{
    		result.setCode("9999");
            result.setMsg("删除失败！");
            logger.info(log+"删除失败！");
    	}
    	return result;
    }
    
    /**
     * 获取通知书信息
     */
    @GetMapping("/getOneTzs")
    public NormalResult getOneTzs(HttpSession session,String n_id){
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
    	NormalResult result = new NormalResult();
    	if (BMUtil.isNullOrEmpty(n_id)) {
            result.setCode("9999");
            result.setMsg("传入申请单ID为空!");
            return result;
        }
    	Map map = new HashMap();
//    	map.put("userid", user.getU_id());
    	map.put("n_id",Integer.parseInt(n_id));
    	List<NoticeDomain> list = tzsService.getTzsApplyList(map);
    	NoticeDomain noticeDomain = list.get(0);
       
        result.setCode("0000");
        result.setMsg("success");
        result.setData(noticeDomain);
        return result;
    }
    
    /**
     * 通知书更新
     */
    @PostMapping("/UpdateTzs")
    public NormalResult UpdateTzs(HttpSession session,NoticeDomain notice) {
    	String log = "内部事项发起通知书更新>>>>>>>>>>>";
    	logger.info(log+"参数【"+notice+"】");
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        try {
        	if(!BMUtil.isNotNull(notice.getN_id())){
        		result.setCode("9999");
                result.setMsg("申请单ID为空！");
                logger.info(log+"申请单ID为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(notice.getN_duetime())){
        		result.setCode("9999");
                result.setMsg("办理期限为空！");
                logger.info(log+"办理期限为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(notice.getN_receive_depid())){
        		result.setCode("9999");
                result.setMsg("接收部门为空！");
                logger.info(log+"接收部门为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(notice.getN_content())){
        		result.setCode("9999");
                result.setMsg("工作事由为空！");
                logger.info(log+"工作事由为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(notice.getN_demand())){
        		result.setCode("9999");
                result.setMsg("工作要求为空！");
                logger.info(log+"工作要求为空！");
                return result;
        	}
        	notice.setN_apply_userid(user.getU_id());
        	notice.setN_apply_depid(user.getD_id());
        	notice.setN_apply_date(BMUtil.getNowTimeForString());
        	int retResult = tzsService.UpdateTzs(notice);
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("更新成功！");
                logger.info(log+"更新成功！");
        	}else{
        		result.setCode("9999");
                result.setMsg("更新失败！");
                logger.info(log+"更新失败！");
        	}
        	return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("申请单更新异常！");
            logger.error(e);
        }
        return result;
    }
    
    /**
     * 申请单提交
     */
    @PostMapping("/upTzs")
    public NormalResult upTzs(NoticeDomain notice) {
    	NormalResult result = new NormalResult();
    	try {
	        if (BMUtil.isNullOrEmpty(notice.getN_id())) {
	            result.setCode("9999");
	            result.setMsg("传入申请单ID为空!");
	            return result;
	        }
	        notice.setN_state("1");
        	int retResult = tzsService.upTzs(notice);
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("提交成功！");
        	}else{
        		result.setCode("9999");
                result.setMsg("提交失败！");
        	}
        	return result;
    	}catch (Exception e) {
            result.setCode("9999");
            result.setMsg("通知书提交异常！");
            logger.error(e);
            return result;
        }        
    }
    
    /**
     * 获取通知书科级审核列表
     */
	@GetMapping("/getTzsKzShList")
    public Object getTzsKzShList(HttpSession session,NoticeDomain notice,Integer page,Integer limit) {
    	Datagrid result = new Datagrid();
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
    	
    	Map map = new HashMap();
		map.put("qs_date", notice.getQs_date());
		map.put("jz_date", notice.getJz_date());
		if(notice.getN_state()==null){
			map.put("n_state", "1");//默认显示表单状态 1--科级未审核
		}else if("".equals(notice.getN_state())){
			map.put("n_state", "1,2,3,4,5,6,7,8");
		}else{
			map.put("n_state", notice.getN_state());
		}
		map.put("n_apply_depid", user.getD_id());
		
		PageHelper.startPage(page, limit);
		List<NoticeDomain> list = tzsService.getTzsApplyList(map);
		PageInfo pagelist = new PageInfo(list);
		
		result.setCode(0);
        result.setMsg("success");
        result.setData(list);
        result.setCount(pagelist.getTotal());

        return result;
    }
	
    /**
     * 通知书科级审核
     */
    @PostMapping("/verifyTzs")
    public NormalResult verifyTzs(HttpSession session,NoticeDomain notice) {
    	String log = "通知书科级审核>>>>>>>>>>>";
    	logger.info(log+"参数【"+notice+"】");
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        try {
        	if(!BMUtil.isNotNull(notice.getN_id())){
        		result.setCode("9999");
                result.setMsg("申请单ID为空！");
                logger.info(log+"申请单ID为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(notice.getN_verify_view())){
        		result.setCode("9999");
                result.setMsg("发起部门意见为空！");
                logger.info(log+"发起部门意见为空！");
                return result;
        	}
        	if("2".equals(notice.getN_state())){
        		if(!BMUtil.isNotNull(notice.getN_bur_userid())){
            		result.setCode("9999");
                    result.setMsg("同意发起通知书，局级领导不可为空！");
                    logger.info(log+"同意发起通知书，局级领导不可为空！");
                    return result;
            	}
        	}
        	notice.setN_verify_userid(user.getU_id());
        	notice.setN_verify_date(BMUtil.getNowTimeForString());
        	int retResult = tzsService.verifyTzs(notice);
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("审核成功！");
                logger.info(log+"审核成功！");
        	}else{
        		result.setCode("9999");
                result.setMsg("审核失败！");
                logger.info(log+"审核失败！");
        	}
        	return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("申请单审核异常！");
            logger.error(e);
        }
        return result;
    }
    
    /**
     * 获取通知书局级审核列表
     */
	@GetMapping("/getTzsJzShList")
    public Object getTzsJzShList(HttpSession session,NoticeDomain notice,Integer page,Integer limit) {
    	Datagrid result = new Datagrid();
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
    	
    	Map map = new HashMap();
		map.put("qs_date", notice.getQs_date());
		map.put("jz_date", notice.getJz_date());
		if(notice.getN_state()==null){
			map.put("n_state", "2");//默认显示表单状态 1--科级审核通过
		}else if("".equals(notice.getN_state())){
			map.put("n_state", "2,4,5,6,7,8");
		}else{
			map.put("n_state", notice.getN_state());
		}
		map.put("n_bur_userid", user.getU_id());
		
		PageHelper.startPage(page, limit);
		List<NoticeDomain> list = tzsService.getTzsApplyList(map);
		PageInfo pagelist = new PageInfo(list);
		
		result.setCode(0);
        result.setMsg("success");
        result.setData(list);
        result.setCount(pagelist.getTotal());

        return result;
    }
	
    /**
     * 通知书科级审核
     */
    @PostMapping("/burTzs")
    public NormalResult burTzs(HttpSession session,NoticeDomain notice) {
    	String log = "通知书局级审核>>>>>>>>>>>";
    	logger.info(log+"参数【"+notice+"】");
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        try {
        	if(!BMUtil.isNotNull(notice.getN_id())){
        		result.setCode("9999");
                result.setMsg("申请单ID为空！");
                logger.info(log+"申请单ID为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(notice.getN_bur_view())){
        		result.setCode("9999");
                result.setMsg("局级领导意见为空！");
                logger.info(log+"局级领导意见为空！");
                return result;
        	}
        	notice.setN_bur_date(BMUtil.getNowTimeForString());
        	int retResult = tzsService.burTzs(notice);
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("审核成功！");
                logger.info(log+"审核成功！");
        	}else{
        		result.setCode("9999");
                result.setMsg("审核失败！");
                logger.info(log+"审核失败！");
        	}
        	return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("申请单审核异常！");
            logger.error(e);
        }
        return result;
    }
    
    /**
     * 获取用户列表
     */
    @GetMapping("/getBmUsers")
    public LayUiDataTablePOJO getBmUsers(NoticeDomain notice) {
        LayUiDataTablePOJO result = tzsService.getUserList(notice.getN_id());
        logger.info(result);
        return result;
    }
    
    /**
     * 获取通知书局级审核列表
     */
	@GetMapping("/getTzsJsList")
    public Object getTzsJsList(HttpSession session,NoticeDomain notice,Integer page,Integer limit) {
    	Datagrid result = new Datagrid();
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
    	
    	Map map = new HashMap();
		map.put("qs_date", notice.getQs_date());
		map.put("jz_date", notice.getJz_date());
		if(notice.getN_state()==null){
			map.put("n_state", "4,7");//默认显示表单状态 4--局级审核通过 7--已反馈等待确认
		}else if("".equals(notice.getN_state())){
			map.put("n_state", "4,6,7,8");
		}else{
			map.put("n_state", notice.getN_state());
		}
		map.put("n_receive_depid", user.getD_id());
		
		PageHelper.startPage(page, limit);
		List<NoticeDomain> list = tzsService.getTzsApplyList(map);
		PageInfo pagelist = new PageInfo(list);
		
		result.setCode(0);
        result.setMsg("success");
        result.setData(list);
        result.setCount(pagelist.getTotal());

        return result;
    }
	
    /**
     * 通知书接收分派
     */
    @PostMapping("/jsTzs")
    public NormalResult jsTzs(HttpSession session,NoticeDomain notice) {
    	String log = "通知书接收分派>>>>>>>>>>>";
    	logger.info(log+"参数【"+notice+"】");
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        try {
        	if(!BMUtil.isNotNull(notice.getN_id())){
        		result.setCode("9999");
                result.setMsg("申请单ID为空！");
                logger.info(log+"申请单ID为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(notice.getN_back_userid())){
        		result.setCode("9999");
                result.setMsg("处理人员为空！");
                logger.info(log+"处理人员为空！");
                return result;
        	}
        	notice.setN_receive_date(BMUtil.getNowTimeForString());
        	notice.setN_receive_userid(user.getU_id());
        	int retResult = tzsService.jsTzs(notice);
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("分派成功！");
                logger.info(log+"分派成功！");
        	}else{
        		result.setCode("9999");
                result.setMsg("分派失败！");
                logger.info(log+"分派失败！");
        	}
        	return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("申请单审核异常！");
            logger.error(e);
        }
        return result;
    }
    
    /**
     * 确认通知书
     */
    @PostMapping("/sureTzs")
    public NormalResult sureTzs(HttpSession session,NoticeDomain notice) {
    	String log = "通知书确认>>>>>>>>>>>";
    	logger.info(log+"参数【"+notice+"】");
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        try {
        	if(!BMUtil.isNotNull(notice.getN_id())){
        		result.setCode("9999");
                result.setMsg("申请单ID为空！");
                logger.info(log+"申请单ID为空！");
                return result;
        	}
        	Map map = new HashMap();
        	map.put("n_id",Integer.parseInt(notice.getN_id()));
        	List<NoticeDomain> list = tzsService.getTzsApplyList(map);
        	if(list.size()==0){
        		result.setCode("9999");
                result.setMsg("无法查询到对应的通知书！");
                logger.info(log+"无法查询到对应的通知书！");
                return result;
        	}
        	NoticeDomain noticeDomain = list.get(0);
        	if(!noticeDomain.getN_receive_userid().equals(user.getU_id())){
        		result.setCode("9999");
                result.setMsg("该通知书非你本人接收并且分派，无法确认！");
                logger.info(log+"该通知书非你本人接收并且分派，无法确认！");
                return result;
        	}
        	int retResult = tzsService.sureTzs(notice);
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("确认成功！");
                logger.info(log+"确认成功！");
        	}else{
        		result.setCode("9999");
                result.setMsg("确认失败！");
                logger.info(log+"确认失败！");
        	}
        	return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("反馈表确认异常！");
            logger.error(e);
        }
        return result;
    }
    
    /**
     * 获取通知书局级审核列表
     */
	@GetMapping("/getTzsBackList")
    public Object getTzsBackList(HttpSession session,NoticeDomain notice,Integer page,Integer limit) {
    	Datagrid result = new Datagrid();
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
    	
    	Map map = new HashMap();
		map.put("qs_date", notice.getQs_date());
		map.put("jz_date", notice.getJz_date());
		if(notice.getN_state()==null){
			map.put("n_state", "6,7,8");//默认显示表单状态 6--已接收 8--领导确认不同意
		}else if("".equals(notice.getN_state())){
			map.put("n_state", "6,7,8");
		}else{
			map.put("n_state", notice.getN_state());
		}
		map.put("n_back_userid", user.getU_id());
		
		PageHelper.startPage(page, limit);
		List<NoticeDomain> list = tzsService.getTzsApplyList(map);
		PageInfo pagelist = new PageInfo(list);
		
		result.setCode(0);
        result.setMsg("success");
        result.setData(list);
        result.setCount(pagelist.getTotal());

        return result;
    }
	
    /**
     * 提交反馈表
     */
    @PostMapping("/uploadTzs")
    public NormalResult uploadTzs(HttpSession session,NoticeDomain notice) {
    	String log = "提交反馈表>>>>>>>>>>>";
    	logger.info(log+"参数【"+notice+"】");
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        try {
        	if(!BMUtil.isNotNull(notice.getN_id())){
        		result.setCode("9999");
                result.setMsg("申请单ID为空！");
                logger.info(log+"申请单ID为空！");
                return result;
        	}
        	if(!BMUtil.isNotNull(notice.getN_back_result())){
        		result.setCode("9999");
                result.setMsg("反馈表内容为空！");
                logger.info(log+"反馈表内容为空！");
                return result;
        	}
        	notice.setN_back_date(BMUtil.getNowTimeForString());
        	int retResult = tzsService.uploadTzs(notice);
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("提交成功！");
                logger.info(log+"提交成功！");
        	}else{
        		result.setCode("9999");
                result.setMsg("提交失败！");
                logger.info(log+"提交失败！");
        	}
        	return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("反馈表提交异常！");
            logger.error(e);
        }
        return result;
    }
    
    @PostMapping(value = "uploadfile")
    public NormalResult uploadfile(HttpSession session,MultipartFile file,String n_id)throws IOException {
        SysUsersPOJO user = (SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        InputStream is = null;
        try {
            // 判断文件是否为空
            if (file == null) {
                result.setCode("9999");
                result.setMsg("文件不能为空！");
                return result;
            }

            // 获取文件名
            String fileName = file.getOriginalFilename();
            
            if (!BMUtil.validateExcel(fileName)&&!fileName.contains(".doc")&&!fileName.contains(".pdf")) {
                result.setCode("9999");
                result.setMsg("文件必须是excel或word文件或pdf文件！");
                return result;
            }

            String pdf_location = "D:\\soft\\nginx\\html\\hzwgs\\upload\\"+n_id+"";
            logger.info("上传文件保存路径：" + pdf_location);
	        File filePath = new File(pdf_location);
	        if (! filePath.exists()) {
	            filePath.mkdirs();
	            logger.info("文件保存路径不存在，创建成功！");
	        }
	        BMUtil.getFile(file.getBytes(), pdf_location, fileName);
	        NoticeDomain notice = new NoticeDomain();
	        notice.setN_id(n_id);
	        notice.setN_filename(fileName);
	        int res = tzsService.UpdateFileName(notice);
	        if(res>0){
	        	result.setCode("0000");
	            result.setMsg("上传成功");
	        }else{
	        	result.setCode("9999");
	            result.setMsg("上传失败");
	        }
            return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("文件上传异常！");
            logger.error(e);
            return result;
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    is = null;
                    e.printStackTrace();
                }
            }
        }
    }
    
    /**
     * 附件删除
     */
    @PostMapping("/deleteFile")
    public NormalResult deleteFile(HttpSession session,String n_id) {
    	String log = "删除附件>>>>>>>>>>>";
    	logger.info(log+"参数n_id【"+n_id+"】");
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        try {
        	if(!BMUtil.isNotNull(n_id)){
        		result.setCode("9999");
                result.setMsg("申请单ID为空！");
                logger.info(log+"申请单ID为空！");
                return result;
        	}
        	int retResult = tzsService.deleteFile(n_id);
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("附件删除成功！");
                logger.info(log+"附件删除成功！");
        	}else{
        		result.setCode("9999");
                result.setMsg("附件删除失败！");
                logger.info(log+"附件删除失败！");
        	}
        	return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("附件删除异常！");
            logger.error(e);
        }
        return result;
    }
    
    @PostMapping(value = "uploadbackfile")
    public NormalResult uploadbackfile(HttpSession session,MultipartFile file,String n_id)throws IOException {
        SysUsersPOJO user = (SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        InputStream is = null;
        try {
            // 判断文件是否为空
            if (file == null) {
                result.setCode("9999");
                result.setMsg("文件不能为空！");
                return result;
            }

            // 获取文件名
            String fileName = file.getOriginalFilename();
            
            if (!BMUtil.validateExcel(fileName)&&!fileName.contains(".doc")&&!fileName.contains(".pdf")) {
                result.setCode("9999");
                result.setMsg("文件必须是excel或word文件或pdf文件！");
                return result;
            }

            String pdf_location = "D:\\soft\\nginx\\html\\hzwgs\\uploadback\\"+n_id+"";
            logger.info("上传文件保存路径：" + pdf_location);
	        File filePath = new File(pdf_location);
	        if (! filePath.exists()) {
	            filePath.mkdirs();
	            logger.info("文件保存路径不存在，创建成功！");
	        }
	        BMUtil.getFile(file.getBytes(), pdf_location, fileName);
	        NoticeDomain notice = new NoticeDomain();
	        notice.setN_id(n_id);
	        notice.setN_back_filename(fileName);
	        int res = tzsService.UpdateBackFileName(notice);
	        if(res>0){
	        	result.setCode("0000");
	            result.setMsg("上传成功");
	        }else{
	        	result.setCode("9999");
	            result.setMsg("上传失败");
	        }
            return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("文件上传异常！");
            logger.error(e);
            return result;
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    is = null;
                    e.printStackTrace();
                }
            }
        }
    }
    
    /**
     * 反馈附件删除
     */
    @PostMapping("/deleteBackFile")
    public NormalResult deleteBackFile(HttpSession session,String n_id) {
    	String log = "删除反馈附件>>>>>>>>>>>";
    	logger.info(log+"参数n_id【"+n_id+"】");
    	SysUsersPOJO user=(SysUsersPOJO) session.getAttribute(Constants.USER_INFO_SESSION);
        NormalResult result = new NormalResult();
        try {
        	if(!BMUtil.isNotNull(n_id)){
        		result.setCode("9999");
                result.setMsg("申请单ID为空！");
                logger.info(log+"申请单ID为空！");
                return result;
        	}
        	int retResult = tzsService.deleteBackFile(n_id);
        	if(retResult>0){
        		result.setCode("0000");
                result.setMsg("附件删除成功！");
                logger.info(log+"附件删除成功！");
        	}else{
        		result.setCode("9999");
                result.setMsg("附件删除失败！");
                logger.info(log+"附件删除失败！");
        	}
        	return result;
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("附件删除异常！");
            logger.error(e);
        }
        return result;
    }
}
